package itsm.isperp.module.controller.sparepart;

import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.configuration.ConfCi;
import itsm.isperp.module.entity.sparepart.SptSparepartChangeDetail;
import itsm.isperp.module.service.sparepart.SptSparepartChangeDetailService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 备件管理控制器
 * 
 * @author lizx
 * @date 2013-9-12
 */
@Controller
@RequestMapping("sparepart/sparepartChangeDetail")
public class SptSparepartChangeDetailController extends
		BaseController<SptSparepartChangeDetail> {

	@Autowired
	protected SptSparepartChangeDetailService sptSparepartChangeDetailService;

	@Override
	public SptSparepartChangeDetailService getService() {
		return sptSparepartChangeDetailService;
	}

	@Override
	public String getPageTitle() {
		return "备件采购项管理";
	}

	@RequestMapping("saveDetails")
	@ResponseBody
	public ResultMessage saveDetails(String relationId, String sparepartIds,String typeKey) {
		String[] sparepartIdArr = sparepartIds.split(",");
		sptSparepartChangeDetailService.batchSave(relationId, sparepartIdArr,typeKey);
		return ResultMessage.success();
	}

	@RequestMapping("listDetails")
	@ResponseBody
	public List<Map<String, Object>> listDetails(String relationId) {

		return this.sptSparepartChangeDetailService
				.findAllDetailByRelationId(relationId);
	}
	
	@RequestMapping("listDetailsBySptSparepartId")
	@ResponseBody
	public PageResponse<Map<String, Object>> listDetailsBySptSparepartId(String sptSparepartId) {

		JqGridRequest jr=new JqGridRequest();
		jr.addFilterRule("spt_sparepart_id", JqGridFilterRuleOp.eq, sptSparepartId);
		return this.sptSparepartChangeDetailService
				.findAllDetailByRequest(jr).toPage();
	}
	
	
	@RequestMapping("listStore")
	@ResponseBody
	public List<Map<String, Object>> listStore(String sparepartId) {

		return this.sptSparepartChangeDetailService
				.listStore(sparepartId);
	}

}
